@extends('admin.layout')

@section('content')
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding-top: 30px; text-align: center;">
        <form class="layui-form" action="{{route('admin.block_type.store')}}" method="post">
            @include('site.block_type._form')
        </form>
    </div>
@endsection
@section('js')
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$
            ,form = layui.form;

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url:data.form.action,
                data:field,
                type:"post",
                dataType:"json",
                success:function(data){
                    if(data.code===0){
                        layer.msg(data.msg, {icon: 6});
                    }else{
                        layer.msg(data.msg, {icon: 5});
                    }
                },
                error:function(data){
                    layer.msg(data.msg);
                }
            });
            parent.layui.table.reload('LAY-app-content-block_type'); //重载表格
            parent.layer.close(index); //再执行关闭
        });
    })
</script>
@endsection
